package web;

import service.impl.CategoryServiceImpl;
import service.impl.ProductServiceImpl;
import ssm.pojo.Category;
import ssm.pojo.Product;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/index")
public class IndexServlet extends BeanUser {


    public void index(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        CategoryServiceImpl cs = new CategoryServiceImpl();
        List<Category> allCategro = cs.findAllCategro();
        //String s = JsonUtils.list2json(allCategro);

        ProductServiceImpl ps = new ProductServiceImpl();
        List<Product> newCate = ps.findCateBydate();
        List<Product> hotCate = ps.findHot();

        request.getSession().setAttribute("allCategro", allCategro);
        request.getSession().setAttribute("newCate", newCate);
        request.getSession().setAttribute("hotCate", hotCate);

        request.getRequestDispatcher("/jsp/index.jsp").forward(request, response);
    }
}
